﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using CourseManagerModels;
using CourseManagerDAL.Helper;
namespace CourseManagerDAL
{
	public class  CourseCategoryService
	{
		public List<CourseCategory> GetCourseCategories()
		{
			//封装sql
			string sql = "select * from CourseCategory";

			SqlDataReader reader = SQLHelper.GetReader(sql);
			List<CourseCategory> results = new List<CourseCategory>();
			//CourseCategory temp = new CourseCategory();
			while (reader.Read())
			{
				//temp.CategoryId = (int)reader["CategoryId"];
				//temp.CategoryName = (string)reader["CategoryName"];
				//results.Add(temp);
				results.Add(new CourseCategory
				{
					CategoryId = (int)reader["CategoryId"],
					CategoryName = reader["CategoryName"].ToString()
				});
			}
			reader.Close();
			return results;

		}
		
	}
}
